﻿using System;
using System.Collections.Generic;
using SimpleFS.Core;
using SimpleFS.Core.Implementations;

namespace SimpleFS.Services.Cache
{
    public class Cache
    {
        private static Cache cache = new Cache();

        protected Dictionary<string, System.IO.Stream> streams;

        private Cache()
        {
            this.streams = new Dictionary<string,System.IO.Stream>();
        }

        public static Cache GetInstance()
        {
            return cache;
        }

        public System.IO.Stream GetStream(IFile file)
        {
            System.IO.Stream stream = this.streams[file.Name];

            if (stream == null)
            {
                stream = file.Read();
                this.streams[file.Name] = stream;
            }

            return stream;
        }
    }
}
